package view;

import java.sql.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;










import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.inject.Inject;

import org.primefaces.context.RequestContext;

import controller.EmployeeController;
import entity.Commissioned;
import entity.Employee;
import entity.PaymentReport;
import service.CommissionedService;
import service.PayReport;

@ManagedBean
public class PayRollPageView {
	@Inject EmployeeController employeeController;
	private List<PaymentReport> report;

	@PostConstruct
	private void LoadReport(){
		report=employeeController.RunPayRollMethod();
	}
	//pagare tutti gli employee nella lista
	public void PayEmployee(){
		Calendar calendar = new GregorianCalendar();
		for(int i=0;i<report.size();i++){
			if(report.get(i).getAmount()>0){
				report.get(i).setPaymentDate(new Date(calendar.getTime().getTime()));
				employeeController.PayEmployee(report.get(i));
			}
		}
		if(report.size()!=0){
			RequestContext.getCurrentInstance().execute("PF('dialogYes').show();");
		}else{
			RequestContext.getCurrentInstance().execute("PF('dialogNo').show();");
		}
	}
	public List<PaymentReport> getReport() {
		return report;
	}

	public void setReport(List<PaymentReport> report) {
		this.report = report;
	}
	
}
